***********************
*Time Series Analysis for the Social Sciences
*Box-Steffensmeier, Freeman, Hitt, and Pevehouse
*
*Chapter 1 replication code
************************

************************
*Figure 1.1
*Use HouseControl.dta
*Source: http://clerk.house.gov/histHigh/Congressional_History/partyDiv.html
************************

graph twoway connected prop_dem year, scheme(s1mono) title(Partisan Control of the U.S. House)

************************
*Figure 1.2 
*Use DurrGilmourWolbrecht_cong_econ.dta
*Source: Durr, Gilmour, and Wolbrecht 1997
*************************

line capp qdate, yaxis(1) yscale(range(50 80) axis(1)) /// 
|| line econexp qdate, scheme(s1mono) yaxis(2) yscale(range(50 100) axis(2)) ///
title(U.S. Congressional Approval and Economic Expectations)

*************************
*Figure 1.3 
*Use australian guns ts data.dta
*Source: Neill & Leigh 2008, replication data from andrewleigh.org
*************************

line fsuic year || line nfsuic year, /// 
scheme(s1mono) title(Firearm and Non-firearm Suicides in Australia)

************************
*Figure 1.4 
*Use sandler_enders_2004.dta
*Source: Sandler and Enders 2004, Table 1
************************

gen attacksnonus = events - attacksus

line attacksnonus year || line attacksus year, ///
scheme(s1mono) title(Terrorist Attacks on U.S. and non-U.S. Interests)

*************************
*Figure 1.5
*Use weisLEV85.dta
*Source: http://web.ku.edu/~keds/data.dir/levant.html
*************************

line ip date || line pi date, ///
scheme(s1mono) title(Israeli-Palestinian Interactions: 1985-2005)

line iu date || line ui date, ///
scheme(s1mono) title(Israeli-U.S. Interactions: 1985-2005)

line up date || line pu date, ///
scheme(s1mono) title(U.S.-Palestinian Interactions: 1985-2005)


************************
*Figure 1.6
*Use UCR.dta
*Source: http://www.fbi.gov/about-us/cjis/ucr/ucr
************************

tsset mdate

line homicide mdate, scheme(s1mono) title(Monthly U.S. Homicides: 1975-1993)


************************
*Figure 1.7
*Use ClintonBushApproval.dta
*Source: http://pollingreport.com/
************************

*All data points 

graph twoway connected approval date2, ///
scheme(s1mono) title(U.S. Presidential Approval Ratings)

graph twoway connected appr_m_lo mdate, ///
scheme(s1mono) title(Last Observation Each Month) 


graph twoway connected appr_q_lo qdate, ///
scheme(s1mono) title(Last Observation Each Quarter)

graph twoway connected appr_yr_lo year, ///
scheme(s1mono) title(Last Observation Each Year)


************************
*Figure 1.8 
*Use chinaevents.dta
*Source: ICPSR Archive No. 2761
************************

*Generate daily and yearly variables
by date: egen us_ch_daily = total(gscale) if src == "USA" 

by date: egen ch_us_daily = total(gscale) if src == "CHN"

gen date2 = mdy(month,day,year+1900)

gen mdate =  mofd(date2)

bysort year: egen U_Cyr = mean(U_Cmo)
bysort year: egen C_Uyr = mean(C_Umo)

line us_ch_daily date2 || line ch_us_daily date2, scheme(s1mono)
title(U.S.-Chinese Relations Daily Aggregation)

line  U_Cmo mdate || line  C_Umo mdate, scheme(s1mono) ///
title(U.S.-Chinese Relations Monthly Aggregation) xlabel(324(24)444)

line U_Cyr year || line C_Uyr year, scheme(s1mono) ///
title(U.S.-Chinese Relations Yearly Aggregation) xlabel(87(2)97)

***************************
*Figure 1.9
*Use Gaza_no_postures.dta
*Source: Zeitzoff 2011, https://sites.google.com/site/zeitzoff/research
****************************

line israel hours || line hamas hours, scheme(s1mono) ///
title(Gaza Conflict By The Hour)

